<?php

namespace Common\Service;


/** 
 * 
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */
Class StatisDayService extends BaseService
{

	public function getTopUser($day, $stat, $except = [])
	{
		$map = [
			'day'		  => (int) $day,
			'object_type' => 'user',
		];

		if ($except) $map['object_id'] = array('nin', array_map('intval', $except));
		$res = $this->where($map)->order("stat.{$stat} desc")->limit(1)->select();
		return $res ? array_values($res)[0]['object_id'] : '';
	}

	public function getTopVideoUser($day, $stat, $except = [])
	{
		$map = [
			'day'		  => (int) $day,
			'object_type' => 'video_user',
		];
		if ($except) $map['object_id'] = array('nin', array_map('intval', $except));
		$res = $this->where($map)->order("stat.{$stat} desc")->limit(1)->select();
		// echo $this->_sql(),'<br/>';
		return $res ? array_values($res)[0]['object_id'] : '';
	}

	public function getTopVideo($day, $stat, $except = [])
	{
		$map = [
			'day'		  => (int) $day,
			'object_type' => 'video',
		];
		if ($except) $map['object_id'] = array('nin', array_map('intval', $except));
		$res = $this->where($map)->order("stat.{$stat} desc")->limit(1)->select();
		return $res ? array_values($res)[0]['object_id'] : '';
	}



}